package com.summli.basic.class01;

/**
 * 局部最小问题，无序数组arr[0~n-1]相邻不等
 */
public class Class01_7_BSAwesome {
    private static int getLessIndex(int[] arr){
        if(arr == null || arr.length ==0){
            return -1;
        }
        if(arr[0] <arr[1]){
            return 0;
        }
        if (arr[arr.length - 2] > arr[arr.length-1]) {
            return arr.length-1;
        }
        int l = 1;
        int r = arr.length-2;
        while(l<=r){
            int mid = l+((r-l)>>1);
            if(arr[mid-1]<arr[mid]){
                r = mid -1;
            }else if (arr[mid] > arr[mid+1]){
                l = mid +1;
            }else{
                return mid;
            }
        }
        return l;
    }
}
